﻿package mortal.game.view.achievement
{
    import Message.Public.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.mui.events.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.achievement.panel.*;
    import mortal.game.view.common.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class AchievementModule extends BaseWindow
    {
        private var _tab:GTabarNew;
        private var _tabData:Array;
        public var curPanel:AchievementCurPanel;
        public var gotPanel:AchievementGotPanel;
        public var uiLoadComplete:Boolean = false;
        private var _openPanelData:Object;

        public function AchievementModule(param1:ILayer = null)
        {
            super(param1);
            this.init();
            return;
        }// end function

        private function init() : void
        {
            this.setSize(830, 620);
            this.titleHeight = 60;
            this.title = "" + Language.getString(60200);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tabData = [{label:Language.getString(70813), name:"curAchi"}];
            LoaderHelp.addResCallBack(ResFileConst.achievement, this.onShowWin);
            return;
        }// end function

        private function onShowWin() : void
        {
            this._tab = UIFactory.gTabBarNew(7, 36, this._tabData, 820, 505, 65, 26, this, this.onTabChangeHd);
            this.curPanel = UICompomentPool.getUICompoment(AchievementCurPanel) as AchievementCurPanel;
            this.curPanel.x = 10;
            this.curPanel.y = 55;
            this.addChild(this.curPanel);
            this.gotPanel = UICompomentPool.getUICompoment(AchievementGotPanel) as AchievementGotPanel;
            this.gotPanel.x = 10;
            this.gotPanel.y = 60;
            this.gotPanel.visible = false;
            this.addChild(this.gotPanel);
            this.onTabChangeHd(null);
            if (this.uiLoadComplete == false)
            {
                this.queryData();
                this.uiLoadComplete = true;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this.uiLoadComplete == false)
            {
                return;
            }
            this._tabData = null;
            this._tab.dispose(param1);
            this._tab = null;
            this.curPanel.dispose(param1);
            this.curPanel = null;
            this.gotPanel.dispose(param1);
            this.gotPanel = null;
            return;
        }// end function

        public function openPageByParam(param1:Object) : void
        {
            this._openPanelData = param1;
            if (this.isHide)
            {
                this.show();
            }
            if (this.uiLoadComplete == false)
            {
                Global.stage.addEventListener(Event.ENTER_FRAME, this.onEnter);
            }
            else
            {
                this.openPage();
            }
            return;
        }// end function

        private function onEnter(event:Event) : void
        {
            if (this.uiLoadComplete)
            {
                Global.stage.removeEventListener(Event.ENTER_FRAME, this.onEnter);
                this.openPage();
            }
            return;
        }// end function

        private function openPage() : void
        {
            var _loc_2:SAchievementType = null;
            var _loc_1:* = this._openPanelData;
            if (_loc_1 is SAchievementCategory)
            {
                this.curPanel.showPanel(0);
            }
            else if (_loc_1 is SAchievementType)
            {
                _loc_2 = _loc_1 as SAchievementType;
                this.curPanel.openTabByIndex(_loc_2.category, _loc_2.type);
            }
            return;
        }// end function

        private function onTabChangeHd(event:MuiEvent) : void
        {
            if (this._tab.selectedIndex == 0)
            {
                this.curPanel.visible = true;
                this.gotPanel.visible = false;
            }
            else
            {
                this.curPanel.visible = false;
                this.gotPanel.visible = true;
            }
            return;
        }// end function

        private function queryData() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.AchievementOnOpenPage));
            return;
        }// end function

    }
}
